package com.atguigu.lease.common.context;

/**
 * ClassName: LoginUserContext
 * Package: com.atguigu.lease.common.context
 * Description:
 *
 * @Autor: xvyy
 * @Create: 2024/11/21 - 16:06
 * @Version: v1.0
 */
public class LoginUserContext {
    //todo 1. 使用ThreadLocal保存登录用户信息
     private static final ThreadLocal<LoginUser> userThreadLocal = new ThreadLocal<>();

     //todo 2. 设置登录用户信息
    public static void setLoginUser(LoginUser loginUser) {
        userThreadLocal.set(loginUser);
    }

    //todo 3. 获取登录用户信息
    public static LoginUser getLoginUser() {
        return userThreadLocal.get();
    }

    //todo 4. 清除登录用户信息
    public static void clear() {
        userThreadLocal.remove();
    }
}
